package Janelas.SQL;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;

import Banco.ConnectionFactory;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JanelaOutros extends JFrame {

	private static final long serialVersionUID = 2L;
	
	private JPanel contentPane;
	private JTextField nomeVitOut;
	private JTextField CPFVitOut;
	private JTextField RGVitOut;
	private JTextField orgExVitOut;
	private JTextField dataNascVitOut;
	private JTextField logrVitOut;
	private JTextField numVitOut;
	private JTextField bairroVitOut;
	private JTextField complVitOut;
	private JTextField CEPVitOut;
	private JTextField telResVitOut;
	private JTextField telCelVitOut;
	private JTextField nomeTestOut;
	private JTextField CPFTestOut;
	private JTextField RGTestOut;
	private JTextField orgExTestOut;
	private JTextField dataNascTestOut;
	private JTextField logrTestOut;
	private JTextField numTestOut;
	private JTextField bairroTestOut;
	private JTextField complTestOut;
	private JTextField CEPTestOut;
	private JTextField telResTestOut;
	private JTextField telCelTestOut;
	private JTextField cityVitOut;
	private JTextField cityTestOut;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;

	public JanelaOutros() {
		setResizable(false);
		setTitle("Outras ocorr\u00EAncias - Occurence Safe");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 672, 665);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("Para continuar o cadastro, preencha os campos abaixo:");
		label.setFont(new Font("Tahoma", Font.PLAIN, 14));
		label.setBounds(10, 11, 350, 14);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("Dados da v\u00EDtima");
		label_1.setFont(new Font("Tahoma", Font.BOLD, 14));
		label_1.setBounds(10, 100, 118, 14);
		contentPane.add(label_1);
		
		JLabel label_2 = new JLabel("Nome:");
		label_2.setBounds(10, 125, 46, 14);
		contentPane.add(label_2);
		
		nomeVitOut = new JTextField();
		nomeVitOut.setColumns(10);
		nomeVitOut.setBounds(50, 122, 596, 20);
		contentPane.add(nomeVitOut);
		
		JLabel label_3 = new JLabel("CPF:");
		label_3.setBounds(20, 150, 46, 14);
		contentPane.add(label_3);
		
		CPFVitOut = new JTextField();
		CPFVitOut.setColumns(10);
		CPFVitOut.setBounds(50, 147, 141, 20);
		contentPane.add(CPFVitOut);
		
		JLabel label_4 = new JLabel("RG:");
		label_4.setBounds(250, 175, 46, 14);
		contentPane.add(label_4);
		
		RGVitOut = new JTextField();
		RGVitOut.setColumns(10);
		RGVitOut.setBounds(274, 172, 95, 20);
		contentPane.add(RGVitOut);
		
		JLabel label_5 = new JLabel("\u00D3rg\u00E3o Expedidor:");
		label_5.setBounds(448, 150, 107, 14);
		contentPane.add(label_5);
		
		orgExVitOut = new JTextField();
		orgExVitOut.setColumns(10);
		orgExVitOut.setBounds(552, 147, 94, 20);
		contentPane.add(orgExVitOut);
		
		JLabel label_6 = new JLabel("Data de Nascimento:");
		label_6.setBounds(10, 175, 118, 14);
		contentPane.add(label_6);
		
		dataNascVitOut = new JTextField();
		dataNascVitOut.setColumns(10);
		dataNascVitOut.setBounds(133, 172, 107, 20);
		contentPane.add(dataNascVitOut);
		
		JLabel label_7 = new JLabel("Logradouro:");
		label_7.setBounds(10, 200, 74, 14);
		contentPane.add(label_7);
		
		logrVitOut = new JTextField();
		logrVitOut.setColumns(10);
		logrVitOut.setBounds(83, 197, 390, 20);
		contentPane.add(logrVitOut);
		
		JLabel label_8 = new JLabel("N\u00FAmero:");
		label_8.setBounds(496, 200, 59, 14);
		contentPane.add(label_8);
		
		numVitOut = new JTextField();
		numVitOut.setColumns(10);
		numVitOut.setBounds(552, 197, 94, 20);
		contentPane.add(numVitOut);
		
		JLabel label_9 = new JLabel("Bairro:");
		label_9.setBounds(10, 225, 46, 14);
		contentPane.add(label_9);
		
		bairroVitOut = new JTextField();
		bairroVitOut.setColumns(10);
		bairroVitOut.setBounds(52, 222, 118, 20);
		contentPane.add(bairroVitOut);
		
		JLabel label_10 = new JLabel("Complemento:");
		label_10.setBounds(197, 225, 87, 14);
		contentPane.add(label_10);
		
		complVitOut = new JTextField();
		complVitOut.setColumns(10);
		complVitOut.setBounds(284, 222, 189, 20);
		contentPane.add(complVitOut);
		
		JLabel label_11 = new JLabel("CEP:");
		label_11.setBounds(496, 225, 46, 14);
		contentPane.add(label_11);
		
		CEPVitOut = new JTextField();
		CEPVitOut.setColumns(10);
		CEPVitOut.setBounds(552, 222, 94, 20);
		contentPane.add(CEPVitOut);
		
		JLabel label_12 = new JLabel("Telefone Residencial:");
		label_12.setBounds(10, 250, 134, 14);
		contentPane.add(label_12);
		
		telResVitOut = new JTextField();
		telResVitOut.setColumns(10);
		telResVitOut.setBounds(136, 247, 157, 20);
		contentPane.add(telResVitOut);
		
		telCelVitOut = new JTextField();
		telCelVitOut.setColumns(10);
		telCelVitOut.setBounds(503, 247, 143, 20);
		contentPane.add(telCelVitOut);
		
		JLabel label_13 = new JLabel("Telefone Celular:");
		label_13.setBounds(403, 250, 107, 14);
		contentPane.add(label_13);
		
		JLabel label_14 = new JLabel("Dados da testemunha");
		label_14.setFont(new Font("Tahoma", Font.BOLD, 14));
		label_14.setBounds(10, 278, 161, 14);
		contentPane.add(label_14);
		
		JLabel label_15 = new JLabel("Nome:");
		label_15.setBounds(10, 303, 46, 14);
		contentPane.add(label_15);
		
		nomeTestOut = new JTextField();
		nomeTestOut.setColumns(10);
		nomeTestOut.setBounds(50, 300, 596, 20);
		contentPane.add(nomeTestOut);
		
		JLabel label_16 = new JLabel("CPF:");
		label_16.setBounds(20, 328, 46, 14);
		contentPane.add(label_16);
		
		CPFTestOut = new JTextField();
		CPFTestOut.setColumns(10);
		CPFTestOut.setBounds(50, 325, 141, 20);
		contentPane.add(CPFTestOut);
		
		JLabel label_17 = new JLabel("RG:");
		label_17.setBounds(250, 353, 46, 14);
		contentPane.add(label_17);
		
		RGTestOut = new JTextField();
		RGTestOut.setColumns(10);
		RGTestOut.setBounds(274, 350, 95, 20);
		contentPane.add(RGTestOut);
		
		JLabel label_18 = new JLabel("\u00D3rg\u00E3o Expedidor:");
		label_18.setBounds(448, 328, 107, 14);
		contentPane.add(label_18);
		
		orgExTestOut = new JTextField();
		orgExTestOut.setColumns(10);
		orgExTestOut.setBounds(552, 325, 94, 20);
		contentPane.add(orgExTestOut);
		
		JLabel label_19 = new JLabel("Data de Nascimento:");
		label_19.setBounds(10, 353, 118, 14);
		contentPane.add(label_19);
		
		dataNascTestOut = new JTextField();
		dataNascTestOut.setColumns(10);
		dataNascTestOut.setBounds(133, 350, 107, 20);
		contentPane.add(dataNascTestOut);
		
		JLabel label_20 = new JLabel("Logradouro:");
		label_20.setBounds(10, 378, 74, 14);
		contentPane.add(label_20);
		
		logrTestOut = new JTextField();
		logrTestOut.setColumns(10);
		logrTestOut.setBounds(83, 375, 390, 20);
		contentPane.add(logrTestOut);
		
		JLabel label_21 = new JLabel("N\u00FAmero:");
		label_21.setBounds(494, 378, 59, 14);
		contentPane.add(label_21);
		
		numTestOut = new JTextField();
		numTestOut.setColumns(10);
		numTestOut.setBounds(552, 375, 94, 20);
		contentPane.add(numTestOut);
		
		JLabel label_22 = new JLabel("Bairro:");
		label_22.setBounds(10, 403, 46, 14);
		contentPane.add(label_22);
		
		bairroTestOut = new JTextField();
		bairroTestOut.setColumns(10);
		bairroTestOut.setBounds(52, 400, 118, 20);
		contentPane.add(bairroTestOut);
		
		JLabel label_23 = new JLabel("Complemento:");
		label_23.setBounds(197, 403, 87, 14);
		contentPane.add(label_23);
		
		complTestOut = new JTextField();
		complTestOut.setColumns(10);
		complTestOut.setBounds(284, 400, 189, 20);
		contentPane.add(complTestOut);
		
		JLabel label_24 = new JLabel("CEP:");
		label_24.setBounds(494, 403, 46, 14);
		contentPane.add(label_24);
		
		CEPTestOut = new JTextField();
		CEPTestOut.setColumns(10);
		CEPTestOut.setBounds(552, 400, 94, 20);
		contentPane.add(CEPTestOut);
		
		JLabel label_25 = new JLabel("Telofone Residencial:");
		label_25.setBounds(10, 427, 134, 14);
		contentPane.add(label_25);
		
		telResTestOut = new JTextField();
		telResTestOut.setColumns(10);
		telResTestOut.setBounds(136, 424, 157, 20);
		contentPane.add(telResTestOut);
		
		JLabel label_26 = new JLabel("Telefone Celular:");
		label_26.setBounds(403, 427, 107, 14);
		contentPane.add(label_26);
		
		telCelTestOut = new JTextField();
		telCelTestOut.setColumns(10);
		telCelTestOut.setBounds(503, 424, 143, 20);
		contentPane.add(telCelTestOut);
		
		JButton button = new JButton("Cancelar");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		button.setBounds(10, 600, 89, 23);
		contentPane.add(button);
		
		JButton button_1 = new JButton("Cadastrar Ocorr\u00EAncia");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Connection con = null;
				String query = null;
				PreparedStatement stmt = null;
				try {
					stmt = con.prepareStatement(query);
				} catch (SQLException e2) {
					e2.printStackTrace();
				}
				
				try {
					con = ConnectionFactory.getConnection();
				} catch (SQLException e) {
					e.printStackTrace();
				}
				try {
					stmt = con.prepareStatement(query);
				} catch (SQLException e) {
					e.printStackTrace();
				}
				query = "INSERT INTO VIOLENCIA_CONTRA_MULHER (ID_OCORRENCIA, CODIGO_VIOLENCIA_CONTRA_MULHER) VALUES (?,?)";
				try {
					
					stmt.setString(1, "");
					stmt.setString(2, textField_2.getText());
					
					stmt.executeUpdate();
					
				} catch (SQLException e1) {

					e1.printStackTrace();
				}

				query = "INSERT INTO VITIMA (ID_OCORRENCIA,NOME_VITIMA, CPF_VITIMA, RG_VITIMA, ORGAO_EXP, DATA_NASC_VITIMA) VALUES (?,?,?,?,?)";
				try {
				
					stmt.setString(1,"" );
					stmt.setString(2, nomeVitOut.getText());
					stmt.setString(3, CPFVitOut.getText());
					stmt.setString(4, RGVitOut.getText());
					stmt.setString(5, orgExVitOut.getText());
					stmt.setString(6, dataNascVitOut.getText());

					stmt.executeUpdate();
					

				} catch (SQLException e1) {

					e1.printStackTrace();
				}
				query = "INSERT INTO TESTEMUNHA (ID_OCORRENCIA, NOME_TESTEMUNHA, CPF_TESTEMUNHA, RG_TESTEMUNHA, DATA_NASC_TESTEMUNHA) VALUES (?,?,?,?,?)";

				try {
					
					stmt.setString(1,"" );
					stmt.setString(2, nomeTestOut.getText());
					stmt.setString(3, CPFTestOut.getText());
					stmt.setString(4, RGTestOut.getText());
					stmt.setString(5, dataNascTestOut.getText());

					stmt.executeUpdate();
					

				} catch (SQLException e1) {
					e1.printStackTrace();
				}
				query = "INSERT INTO ENDERECO (ID_OCORRENCIA, LOGRADOURO, NUMERO, BAIRRO, COMPLEMENTO, CIDADE, ESTADO, CEP) VALUES (?,?,?,?,?,?,?,?)";

				try {
				
					stmt.setString(1,"" );
					stmt.setString(2, logrVitOut.getText());
					stmt.setString(3, numVitOut.getText());
					stmt.setString(4, bairroVitOut.getText());
					stmt.setString(5, complVitOut.getText());
					stmt.setString(6, cityVitOut.getText());
					stmt.setString(7, textField.getText());
					stmt.setString(8, CEPVitOut.getText());

					stmt.executeUpdate();
					
				} catch (SQLException e1) {
					e1.printStackTrace();
				}

				query = "INSERT INTO ENDERECO (ID_OCORRENCIA, LOGRADOURO, NUMERO, BAIRRO, COMPLEMENTO, CIDADE, ESTADO, CEP) VALUES (?,?,?,?,?,?,?,?)";
				try {
					
					stmt.setString(1,"" );
					stmt.setString(2, logrTestOut.getText());
					stmt.setString(3, numTestOut.getText());
					stmt.setString(4, bairroTestOut.getText());
					stmt.setString(5, complTestOut.getText());
					stmt.setString(6, cityTestOut.getText());
					stmt.setString(7, textField_1.getText());
					stmt.setString(8, CEPTestOut.getText());
					
					stmt.executeUpdate();
					

				} catch (SQLException e1) {
					e1.printStackTrace();
				}
				query = "INSERT INTO TELEFONES (ID_OCORRENCIA, FONE1, FONE2, FONE3) VALUES (?,?,?,?)";
				try {
					;
					stmt.setString(1,"" );
					stmt.setString(2, telResVitOut.getText());
					stmt.setString(3, telCelVitOut.getText());
					stmt.setString(4, " ");

					stmt.executeUpdate();
					

				} catch (SQLException e1) {
					e1.printStackTrace();
				}

				query = "INSERT INTO TELEFONES (ID_OCORRENCIA, FONE1, FONE2, FONE3) VALUES (?,?,?,?)";
				try {
				
					stmt.setString(1,"" );
					stmt.setString(2, telResTestOut.getText());
					stmt.setString(3, telCelTestOut.getText());
					stmt.setString(4, " ");
					
					stmt.executeUpdate();
					stmt.close();
					con.close();

				} catch (SQLException e1) {
					e1.printStackTrace();
				}
				nomeVitOut.getText().toString().trim();
				CPFVitOut.getText().toString().trim();
				RGVitOut.getText().toString().trim();
				orgExVitOut.getText().toString().trim();
				dataNascVitOut.getText().toString().trim();
				logrVitOut.getText().toString().trim();
				numVitOut.getText().toString().trim();
				bairroVitOut.getText().toString().trim();
				complVitOut.getText().toString().trim();
				CEPVitOut.getText().toString().trim();
				telResVitOut.getText().toString().trim();
				telCelVitOut.getText().toString().trim();
				nomeTestOut.getText().toString().trim();
				CPFTestOut.getText().toString().trim();
				RGTestOut.getText().toString().trim();
				orgExTestOut.getText().toString().trim();
				dataNascTestOut.getText().toString().trim();
				logrTestOut.getText().toString().trim();
				numTestOut.getText().toString().trim();
				bairroTestOut.getText().toString().trim();
				complTestOut.getText().toString().trim();
				CEPTestOut.getText().toString().trim();
				telResTestOut.getText().toString().trim();
				telCelTestOut.getText().toString().trim();
				cityVitOut.getText().toString().trim();
				cityTestOut.getText().toString().trim();
				
				JOptionPane.showMessageDialog(null, "Cadastro realizado com sucesso!");
				dispose();
				
			}
		});
		button_1.setBounds(485, 600, 161, 23);
		contentPane.add(button_1);
		
		JLabel label_27 = new JLabel("Observa\u00E7\u00F5es:");
		label_27.setBounds(10, 460, 89, 14);
		contentPane.add(label_27);
		
		JTextArea obsTestOut = new JTextArea();
		obsTestOut.setLineWrap(true);
		obsTestOut.setBounds(98, 455, 527, 134);
		contentPane.add(obsTestOut);
		
		JLabel lblCidade = new JLabel("Cidade:");
		lblCidade.setBounds(379, 175, 59, 14);
		contentPane.add(lblCidade);
		
		cityVitOut = new JTextField();
		cityVitOut.setBounds(436, 172, 210, 20);
		contentPane.add(cityVitOut);
		cityVitOut.setColumns(10);
		
		JLabel label_28 = new JLabel("Cidade: *");
		label_28.setBounds(379, 353, 59, 14);
		contentPane.add(label_28);
		
		cityTestOut = new JTextField();
		cityTestOut.setColumns(10);
		cityTestOut.setBounds(436, 350, 210, 20);
		contentPane.add(cityTestOut);
		
		JLabel label_29 = new JLabel("Estado:");
		label_29.setBounds(212, 150, 46, 14);
		contentPane.add(label_29);
		
		textField = new JTextField();
		textField.setColumns(10);
		textField.setBounds(258, 147, 118, 20);
		contentPane.add(textField);
		
		JLabel label_30 = new JLabel("Estado:");
		label_30.setBounds(229, 328, 46, 14);
		contentPane.add(label_30);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(274, 325, 118, 20);
		contentPane.add(textField_1);
		
		JLabel label_31 = new JLabel("C\u00F3digo:");
		label_31.setBounds(10, 72, 46, 14);
		contentPane.add(label_31);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(66, 69, 86, 20);
		contentPane.add(textField_2);
		
		JLabel label_32 = new JLabel("C\u00F3digo da ocorr\u00EAncia");
		label_32.setFont(new Font("Tahoma", Font.BOLD, 14));
		label_32.setBounds(10, 36, 199, 20);
		contentPane.add(label_32);
		
		JLabel label_33 = new JLabel("Occurence Safe");
		label_33.setFont(new Font("Trebuchet MS", Font.BOLD | Font.ITALIC, 21));
		label_33.setBounds(504, 11, 152, 25);
		contentPane.add(label_33);
	}

}
